package com.pricl.frame.core;

import com.wordnik.swagger.annotations.ApiModel;
import com.wordnik.swagger.annotations.ApiModelProperty;

/**
 * <p>
 * 结果类
 * </p>
 * 
 * @author cheng(iknoweth@yahoo.com)
 * @date 2016-5-4 下午10:18:26
 */
@ApiModel(value="结果集")
public class R {
	public static R ok() {
		return new R(1, null, null);
	}

	public static R ok(int code) {
		return new R(code, null, null);
	}

	public static R ok(Object data) {
		return new R(1, data, null);
	}

	public static R ok(String msg) {
		return new R(1, null, msg);
	}

	public static R ok(int code, Object data, String msg) {
		return new R(code, data, msg);
	}

	public static R error() {
		return new R(-1, null, null);
	}

	public static R error(int code) {
		return new R(code, null, null);
	}

	public static R error(String msg) {
		return new R(-1, null, msg);
	}

	public static R error(Object data) {
		return new R(-1, data, null);
	}

	public static R error(int code, Object data, String msg) {
		return new R(code, data, msg);
	}

	public static R data(Object data) {
		return new R(data != null ? 1 : -1, data, null);
	}

	public static R exception(Throwable t) {
		R r = new R(-1, null, t.getMessage());
		if (t instanceof E) {
			E e = (E) t;
			r.code = e.code;
			r.data = e.data;
		}
		return r;
	}

//	public static R exception(Throwable t) {
//		R r = new R(-1, t.getMessage());
//		if (t instanceof E) {
//			E e = (E) t;
//			r.code = e.code;
//			r.data = e.data;
//		}
//		r.error = t.getMessage();
//		return r;
//	}
	/** 代码 **/
	@ApiModelProperty(value="code")
	public int code;

	/** 数据 **/
	@ApiModelProperty(value="数据")
	public Object data;

	/** 消息 **/
	@ApiModelProperty(value="消息")
	public String msg;
	
	/** 错误消息 **/
	@ApiModelProperty(value="dd")
	public String error;

	public R() {
		super();
	}

	public R(int code, Object data, String msg) {
		super();
		this.code = code;
		this.data = data;
		this.msg = msg;
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}
}
